<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class Houseattr extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'houseattr';

    /**
     * @param $parentFiled
     * @return array
     * 获取子级或所有顶级
     */
    public static function getHouseattrData($parentFiled)
    {
        //存储处理后的房源属性
        $houseattr = [];
        //判断是否查询顶级
        if($parentFiled!==0){
            //非 查询该顶级的id
            $parentFiled = self::where('filed_name',$parentFiled)->get()->pluck('id');
        }else{
            $houseattr[0] = '顶级';
        }
        //查询所有顶级或该字段的子级
        $houseattrData = self::where('pid',$parentFiled)->get();
        //处理对象
        foreach ($houseattrData as $v) {
            $houseattr[$v->id] = $v->name;
        }
        return $houseattr;
    }


    public static function skxgetHouseattrData($parentFiled)
    {
        $parentFiled = self::where('filed_name',$parentFiled)->get()->pluck('id');
        $houseattrData = self::where('pid',$parentFiled)->get();
        return $houseattrData;
    }
}

